import { JsonController, Authorized, Body, HeaderParam, Get, Post, UseBefore, QueryParam} from 'routing-controllers';
import { RequestLog } from '@/middleware/requestLog'
import { Inject, Service } from 'typedi';
import { ArticleServiceImpl } from '@/impl/ArticleServiceImpl';
import { JsonResult, msgList, res } from '@/utils/jsonResult';
import { User } from '@/m_res/user'
import {CommentParams } from "@/model/request/Comment";
import config from '@/config'
import { Token } from '@/m_req/Token'

@Service()
@JsonController(config.setPrefix("app/article"))
export class ArticleController {

  @Inject()
  articleServiceImpl!: ArticleServiceImpl;

  @Inject()
  json!: JsonResult<any>;

  /**
 * @api {get} /app/user/info/:id info
 * @apiDescription 获取用户的详细信息
 * @apiName info
 * @apiGroup user
 * @apiParam {number} id 用户的id参数
 * 
 * @apiSuccess {Object} data  用户数据存放在data内部
 * @apiSuccess {Number} data.user_id   用户id
 * @apiSuccess {String} data.user_name   用户名
 * @apiSuccess {String} data.user_pwd   用户密码
 * @apiSuccess {Number} data.user_phone   用户手机号
 * @apiSuccess {String} data.user_img  用户头像
 * @apiSuccess {String} data.user_addtime  注册时间

 * @apiSuccessExample {json} 请求成功的返回:
 *  {
 *      "code" : 200,
 *      "msg" : "请求成功"
 *      "data" : {
 *           user_id: 1,
 *           user_name: "bmy",
 *           user_pwd: "714500",
 *           user_phone: 15056042604,
 *           user_img: "https://www.baidu.com/img/flexible/logo/pc/result@2.png",
 *           user_addtime: "2023-06-03T12:25:16.000Z"
 *      }
 *  }
 * @apiErrorExample {json} 请求失败的返回
 * {
 *   "code": 200,
 *   "msg" : "请求成功"
 *   "data": null
 * }
 * @apiSampleRequest http://127.0.0.1:3000/app/user/info
 */
  @Get('/articleList')
  @UseBefore(RequestLog)
  async GetArticleList(@QueryParam("text") text: string) {
    return await this.articleServiceImpl.GetArticleList(text);
  }


  @Get('/info')
  @UseBefore(RequestLog)
  async GetArticleInfo(@QueryParam("id") id: number) {
    return await this.articleServiceImpl.GetArticleInfo(id);
  }


  @Get('/categories_list')
  @UseBefore(RequestLog)
  async GetCategoriesList() {
    return await this.articleServiceImpl.GetCategoriesList();
  }

  @Get('/categories_info')
  @UseBefore(RequestLog)
  async GetCategoriesInfo(@QueryParam("id") id: number) {
    return await this.articleServiceImpl.GetCategoriesInfo(id);
  }

  @Get('/search')
  @UseBefore(RequestLog)
  async Getsearch(@QueryParam("word") word: string) {
    return await this.articleServiceImpl.GetSearch(word);
  }

  
  @Post('/push_comment')
  @UseBefore(RequestLog)
  @Authorized()
  async PushComment(@Body() params: CommentParams, 
  @HeaderParam("token") token: Token) {
    return await this.articleServiceImpl.pushComment(params, token);
  }


}

